<script>
export default {
  // 系统菜单
  MenuArr: [],
  // 【后台表-模块】数据
  TableFieldData: [],

  // 检查-所有缓存,并赋值
  checkCache: function () {
    var arr = ['TableFieldData']
    var $this = this
    arr.forEach(function (key, _) {
      $this[key] = $this.getCache(key)
    })
  },

  // 获取-单个键缓存
  getCache: function (key) {
    var localString = null
    if (key === 'TableFieldData') {
      localString = localStorage.getItem(key + 'Cache')
    }
    if (typeof localString !== 'string') {
      return null
    }
    if (localString === '' || localString === null) {
      return null
    }
    return JSON.parse(localString)
  },

  // 设置单个键,缓存
  setCache: function (key, value) {
    // 清空
    if (value === null) {
      if (key === 'TableFieldData') {
        localStorage.removeItem(key + 'Cache')
        this.ModuleCache = null
      }
      return
    }
    // 有值
    if (key === 'TableFieldData') {
      localStorage.setItem(key + 'Cache', JSON.stringify(value))
    }
    this.checkCache()
  }
}
</script>
<style scoped>
</style>
